﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using LTP.Accounts.Bus;

namespace TCS.Web.Admin
{
    public partial class NewLeft : System.Web.UI.Page
    {
        AccountsPrincipal user;
        User currentUser;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                str = "";
                user = new AccountsPrincipal(Context.User.Identity.Name);
                if (Session["UserInfo"] == null)
                {
                    return;
                }
                currentUser = (LTP.Accounts.Bus.User)Session["UserInfo"];
                DBind();
            }
        }

        public static string str = "";
        private TCS.BLL.SysManage sm = new TCS.BLL.SysManage();


        private void DBind()
        {
            DataTable dt = sm.GetTreeList("").Tables[0];
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["PermissionID"].ToString() =="-1" || (user.HasPermissionID(int.Parse(dt.Rows[i]["PermissionID"].ToString()))))
                    {
                        if (dt.Rows[i]["parentid"].ToString() == "0")
                        {
                            str += "<h1 class=type><a href='javascript:void(0)' >" + dt.Rows[i]["Text"].ToString() + "</a></h1>"
                            + "<div class=content><ul class=MM>"
                            + GetListJD(dt.Rows[i]["Nodeid"].ToString())
                            + "</ul></div>";
                        }
                    }
                }
            }
        }

        private string GetListJD(string parentid)
        {
            string s = "";
            //string strWhere = " e.username='" + currentUser.UserName + "'and a.parentid=" + parentid;
            string strWhere = " parentid=" + parentid;
            DataTable dtJD = sm.GetTreeList(strWhere).Tables[0];
            if (dtJD.Rows.Count > 0)
            {
                for (int i = 0; i < dtJD.Rows.Count; i++)
                {
                    if (dtJD.Rows[i]["PermissionID"].ToString() == "-1" || (user.HasPermissionID(int.Parse(dtJD.Rows[i]["PermissionID"].ToString()))))
                    {
                        s += "<li><a href='" + dtJD.Rows[i]["Url"].ToString() + "' target='mainFrame'>" + dtJD.Rows[i]["Text"].ToString() + "</a></li>";
                    }
                }
            }
            return s;
        }
    }
}
